/*
 * main.c
 *
 *  Created on: 2018年8月19日
 *      Author: lcp
 */
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>


bool is_pure(long long number);

int main()
{
    printf("Hello World!\n");

    FILE* f;
    f = fopen( "/home/lcp/LCP_LAB/c-speed-test/pure_number.txt", "w" );
    long long end_num=(long long)pow(10,6);
    printf("%lld\n",end_num);
    clock_t start,finish;
    double totaltime;
    start=clock();

    for(long long k=3;k<=end_num;k++)
    {
        if(is_pure(k)==true)
        {
            //printf("%lld",k);
            
            //sprintf(buffer, "%lld", k);
            fprintf(f, "%lld\n", k);
            //fwrite(buffer,sizeof (char)*100,1,f);
        }
    }
    fclose(f);
    finish=clock();
    totaltime=(double)(finish-start)/CLOCKS_PER_SEC;
    printf("time is %f",totaltime);
   // fflush(stdout);
    getchar();
   
    return 0;
}

bool is_pure(long long number)
{
    long long i;
    for(i=2;i<sqrt(number) ;i++)
    {
        if(number%i==0)
        {
            return false;
        }
    }
    return true;
}
